import 'package:shared_preferences/shared_preferences.dart';

class SpProvider {
  SpProvider._();
  SharedPreferences? _sp;
  static final SpProvider spProvider = SpProvider._();

  Future<SharedPreferences> get sp async {
    if (_sp != null) {
      return _sp!;
    }
    _sp = await createDatabase();
    return _sp!;
  }

  Future<SharedPreferences> createDatabase() async {
    return await SharedPreferences.getInstance();
  }

  void setValue(String key, String value) async {
    final db = await sp;
    db.setString(key, value);
  }

  Future<String> getValue(String key) async {
    final db = await sp;
    return db.getString(key) ?? '';
  }

  Future<List<String>> getStringList(String key) async {
    final db = await sp;
    return db.getStringList(key) ?? [];
  }

  void setStringList(String key, List<String> value) async {
    final db = await sp;
    db.setStringList(key, value);
  }
}
